package com.qhp.androidsocket;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.Socket;

public class MainActivity extends AppCompatActivity {

    EditText etIp;
    EditText etDk;
    int finalDkh1;
    String ip1;
    Button btn_home;
    public static int panduan;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btn_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, IndexActivity.class);
                MainActivity.this.startActivity(intent);
            }
        });

    }
    private void initView() {
        etIp = (EditText) findViewById(R.id.et_ip);
        etDk = (EditText) findViewById(R.id.et_dk);
        btn_home=(Button)findViewById(R.id.btn_home);
    }
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_conn:
                ip1 = etIp.getText().toString().trim();
                String dk = etDk.getText().toString().trim();
                int dkh = 0;
                try {
                    dkh = Integer.parseInt(dk);
                }
                catch (Exception e) {
                    Toast.makeText(this, "端口请输入数字", Toast.LENGTH_SHORT).show();
                }
                finalDkh1 = dkh;
                if (panduan==1) {
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this, CzActivity.class);
                    CzActivity czActivity = new CzActivity();
                    czActivity.ip = ip1;
                    czActivity.finalDkh = finalDkh1;
                    czActivity.wifipd=1;
                    MainActivity.this.startActivity(intent);
                }
                if (panduan==2)
                {
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this, OrderActivity.class);
                    OrderActivity czActivity = new OrderActivity();
                    OrderActivity.ip = ip1;
                    OrderActivity.finalDkh = finalDkh1;
                    MainActivity.this.startActivity(intent);
                }
                break;
            default:
                break;
        }
    }
}
